package cn.sciento.boot.transfer.api.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import cn.sciento.boot.transfer.domain.entity.ProducerEvent;

@ApiModel("事件错误监控")
public class EventErrorDTO {
  @ApiModelProperty("表ID，主键。全局ID")
  private Long eventId;
  
  @ApiModelProperty(value = "事件类型", required = true)
  @NotBlank
  private String eventType;
  
  @ApiModelProperty(value = "服务名", required = true)
  @NotBlank
  private String sourceService;
  
  @ApiModelProperty(value = "处理表，也是消息TOPIC", required = true)
  @NotBlank
  private String sourceTable;
  
  @ApiModelProperty("处理数据ID")
  private Long sourceKeyId;
  
  @ApiModelProperty("处理数据租户ID")
  private Long sourceTenantId;
  
  @ApiModelProperty("目标服务名")
  private String targetService;
  
  @ApiModelProperty(value = "消息产生时间", required = true)
  @NotNull
  private Date produceTime;
  
  @ApiModelProperty("消息内容")
  private String messages;
  
  @ApiModelProperty(value = "重试次数", required = true)
  @NotNull
  private Long retryTimes;
  
  @ApiModelProperty(value = "出错类型，参考HDTT.EVENT_ERR_TYPE", required = true)
  @NotBlank
  private String errorType;
  
  @ApiModelProperty("出错时间")
  private Date errorTime;
  
  @ApiModelProperty("错误消息")
  private String errorText;
  
  @ApiModelProperty(value = "处理状态，参考：HDTT.EVENT_PROCESS_STATUS", required = true)
  @NotBlank
  private String processStatus;
  
  @ApiModelProperty("处理消息")
  private String processMsg;
  
  @ApiModelProperty("处理时间")
  private Date processTime;
  
  public static EventErrorDTO getInstance(ProducerEvent producerEvent, String errorType, String errorMsg) {
    EventErrorDTO eventError = new EventErrorDTO();
    eventError.setEventId(producerEvent.getEventId());
    eventError.setEventType(producerEvent.getEventType());
    eventError.setMessages(producerEvent.getMessages());
    eventError.setProduceTime(producerEvent.getProduceTime());
    eventError.setSourceTable(producerEvent.getSourceTable());
    eventError.setSourceService(producerEvent.getSourceService());
    eventError.setErrorTime(new Date());
    eventError.setErrorText(errorMsg);
    eventError.setErrorType(errorType);
    eventError.setRetryTimes(Long.valueOf(0L));
    eventError.setProcessStatus("P");
    return eventError;
  }
  
  public Long getEventId() {
    return this.eventId;
  }
  
  public void setEventId(Long eventId) {
    this.eventId = eventId;
  }
  
  public String getEventType() {
    return this.eventType;
  }
  
  public void setEventType(String eventType) {
    this.eventType = eventType;
  }
  
  public String getSourceService() {
    return this.sourceService;
  }
  
  public void setSourceService(String sourceService) {
    this.sourceService = sourceService;
  }
  
  public String getSourceTable() {
    return this.sourceTable;
  }
  
  public void setSourceTable(String sourceTable) {
    this.sourceTable = sourceTable;
  }
  
  public Long getSourceKeyId() {
    return this.sourceKeyId;
  }
  
  public void setSourceKeyId(Long sourceKeyId) {
    this.sourceKeyId = sourceKeyId;
  }
  
  public Long getSourceTenantId() {
    return this.sourceTenantId;
  }
  
  public void setSourceTenantId(Long sourceTenantId) {
    this.sourceTenantId = sourceTenantId;
  }
  
  public String getTargetService() {
    return this.targetService;
  }
  
  public void setTargetService(String targetService) {
    this.targetService = targetService;
  }
  
  public Date getProduceTime() {
    return this.produceTime;
  }
  
  public void setProduceTime(Date produceTime) {
    this.produceTime = produceTime;
  }
  
  public String getMessages() {
    return this.messages;
  }
  
  public void setMessages(String messages) {
    this.messages = messages;
  }
  
  public Long getRetryTimes() {
    return this.retryTimes;
  }
  
  public void setRetryTimes(Long retryTimes) {
    this.retryTimes = retryTimes;
  }
  
  public String getErrorType() {
    return this.errorType;
  }
  
  public void setErrorType(String errorType) {
    this.errorType = errorType;
  }
  
  public Date getErrorTime() {
    return this.errorTime;
  }
  
  public void setErrorTime(Date errorTime) {
    this.errorTime = errorTime;
  }
  
  public String getErrorText() {
    return this.errorText;
  }
  
  public void setErrorText(String errorText) {
    this.errorText = errorText;
  }
  
  public String getProcessStatus() {
    return this.processStatus;
  }
  
  public void setProcessStatus(String processStatus) {
    this.processStatus = processStatus;
  }
  
  public String getProcessMsg() {
    return this.processMsg;
  }
  
  public void setProcessMsg(String processMsg) {
    this.processMsg = processMsg;
  }
  
  public Date getProcessTime() {
    return this.processTime;
  }
  
  public void setProcessTime(Date processTime) {
    this.processTime = processTime;
  }
}
